package myTask02;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.List;

public class Demo01 {
    public static void main(String[] args) throws DocumentException {
        SAXReader saxReader = new SAXReader();
        Document read = saxReader.read("Day15/XML/books.xml");
        Element rootElement = read.getRootElement();
        List<Element> bookElements = rootElement.elements("book");
        for (Element bookElement : bookElements) {
            String id = bookElement.attributeValue("id");
            System.out.println("id = " + id);
            String name = bookElement.elementText("name");
            System.out.println(name);
            String chuBan = bookElement.elementText("chuBan");
            System.out.println(chuBan);
            String date = bookElement.elementText("date");
            System.out.println(date);
            String price = bookElement.elementText("price");
            System.out.println(price);
        }


    }
}
